/**
 * Magic Menu 1.2
 * Author: Mac_J@boarsoft.com
 * Need: core.js, contextMenu.js
 */
(function($){
mac.menu = function(self, cfg) {
	cfg = $.extend({
		itemHeight : 24,
		marginLeft : 24
	}, cfg);
	self.addItems = function(p, items, l) {
		$.each(items, function(n, c) {
			var a = $('<li></li>'), x = c.icon || 'icon-none';
			if (c.style)
				a.addClass(c.style);
			a.attr('level', l);
			var lc = $('<span class="icon"></span>').addClass(x);
			if (c.children) {
				var rc = $('<span class="icon icon-triangle-1-e"></span>');
				rc.css('float', 'right').appendTo(a);
				var m = $('<ul></ul>');
				if(c.submenuWidth){
					//m.attr('width', c.submenuWidth);
					m.width(c.submenuWidth);
				}
				self.addItems(m, c.children, l + 1);
				a.append(m);
			}
			var tt = $('<span class="title"></span>').append(c.title);
			a.append(lc).append(tt).attr('action', c.action);
			a.height(cfg.itemHeight);
			p.append(a);
		});
	}
	self.addItems(self, cfg.children, 1);
	return self.hide();
}
})(jQuery);